@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './mixin.less';


@datePicker-prefix-cls: ~'@{kd-prefix}-date-picker';
@datePicker-prefix-cls-panel: ~'@{datePicker-prefix-cls}-panel';

@datePicker-calendar-text: 24px;
@datePicker-calendar-height: 242px;

.@{datePicker-prefix-cls} {
  .input-wrapper;
  width: @date-width;

  &-small {
    .input-size(@date-small-height, @date-small-font-size, @date-small-padding-vertical, @date-small-padding-horizontal);

    input {
      font-size: @date-small-font-size;
    }
  }

  &-large {
    .input-size(@date-large-height, @date-large-font-size, @date-small-padding-vertical, @date-small-padding-horizontal);

    input {
      font-size: @date-large-font-size;
    }
  }

  &-middle {
    .input-size(@date-middle-height, @date-middle-font-size, @date-small-padding-vertical, @date-small-padding-horizontal);

    input {
      font-size: @date-middle-font-size;
    }
  }

  &-input {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
    top: 0;

    input {
      .input;
      line-height: inherit;
      flex: auto;
      min-width: 1px;
      height: auto;
      padding: 0;
      background: transparent;
      border: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &[disabled] {
        background: transparent;
      }

      &::placeholder {
        color: @date-input-color-placeholder;
      }
    }

    &-placeholder {
      > input {
        color: @date-input-color-placeholder;
      }
    }
  }

  &-range {
    display: inline-flex;
    align-items: center;
    position: relative;

    &-separator {
      display: inline-block;
      padding: 0 8px;
    }

    .@{datePicker-prefix-cls}-clear {
      right: @date-small-padding-horizontal;
    }

    .@{datePicker-prefix-cls}-active-bar {
      bottom: -1px;
      height: 2px;
      margin-left: 11px;
      background: @date-bar-color-bg-active;
      opacity: 0;
      transition: all 0.3s ease-out;
      pointer-events: none;
    }

    &.@{datePicker-prefix-cls}-focused {
      .@{datePicker-prefix-cls}-active-bar {
        opacity: 1;
      }
    }
  }

  &-suffix {
    align-self: center;
    margin-left: @date-suffix-spacing-margin-left;
    color: @date-input-color;
    line-height: 1;
    pointer-events: none;

    > * {
      vertical-align: top;
    }
  }

  &:not(.@{datePicker-prefix-cls}-disabled):hover {
    .@{datePicker-prefix-cls}-clear {
      opacity: 1;
    }
  }

  &-clear {
    position: absolute;
    top: 50%;
    right: 0;
    color: @date-icon-color;
    line-height: 1;
    background: @date-clear-background-color;
    transform: translateY(-48%);
    cursor: pointer;
    opacity: 0;

    > * {
      vertical-align: top;
    }

    &:hover {
      color: @date-icon-color-hover;
    }
  }

  .@{datePicker-prefix-cls}-range-clear {
    align-self: center;
    margin-left: @date-suffix-spacing-margin-left;
    color: @date-icon-color;
    line-height: 1;
    cursor: pointer;

    &:hover {
      color: @date-icon-color-hover;
    }
  }

  &-focused {
    .@{datePicker-prefix-cls}-suffix {
      color: @date-clear-background-color-focused;
    }
  }

  &-error {
    border-color: @color-error;
  }
}

.@{datePicker-prefix-cls-panel} {
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  border-radius: @date-panel-border-radius;
  background-color: #fff;
  text-align: center;
  z-index: @date-panel-z-index;
  font-size: @date-panel-font-size;

  &-range {
    display: flex;
  }

  &.hidden {
    opacity: 0;
    visibility: hidden;
    transition: all calc(0.3s - 0.1s) cubic-bezier(0.4, 0, 0.6, 1);
  }

  .@{datePicker-prefix-cls}-warpper {
    font-size: 12px;
    background: @date-wrapper-color-background;

    .@{datePicker-prefix-cls}-month,
    .@{datePicker-prefix-cls}-year,
    .@{datePicker-prefix-cls}-quarter {
      width: 240px;
      padding: 8px 12px;
      box-sizing: border-box;
    }

    .@{datePicker-prefix-cls}-year-warpper,
    .@{datePicker-prefix-cls}-month-line {
      display: grid;
      grid-template-columns: 33.33% 33.33% 33.33%;
    }

    .@{datePicker-prefix-cls}-month-item,
    .@{datePicker-prefix-cls}-year-item,
    .@{datePicker-prefix-cls}-quarter-item,
    .@{datePicker-prefix-cls}-calendar-item {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 32px;
      padding-bottom: 8px;
      color: #212121;
    }

    .@{datePicker-prefix-cls}-year-text,
    .@{datePicker-prefix-cls}-month-text,
    .@{datePicker-prefix-cls}-quarter-text {
      line-height: 24px;
      display: inline-block;
      border-radius: @date-panel-border-radius;
    }

    .@{datePicker-prefix-cls}-year {
      &-warpper {
        .@{datePicker-prefix-cls}-year-item {
          overflow: hidden;
          cursor: pointer;

          &:hover {
            .@{datePicker-prefix-cls}-year-text {
              &:not(.@{datePicker-prefix-cls}-year-text-selected) {
                background: #f5f5f5;
              }
            }

            &:not(.@{datePicker-prefix-cls}-year-item-disabled) {
              .@{datePicker-prefix-cls}-year-text-selected {
                background: @date-square-item-color-selected;
              }
            }
          }

          .@{datePicker-prefix-cls}-year-text {
            position: relative;
            z-index: 2;
            width: 46px;
            padding: 2px 2px;
          }

          .@{datePicker-prefix-cls}-year-text-today {
            .today-after(@date-color-background-checked);
          }

          &-disabled {
            pointer-events: none;

            .@{datePicker-prefix-cls}-year-text {
              color: #b2b2b2;
              background: #f5f5f5;
            }
          }

          .@{datePicker-prefix-cls}-year-text-selected {
            background: @date-color-background-checked;
            color: #fff;
          }
        }
      }

      .@{datePicker-prefix-cls}-range-view,
      .@{datePicker-prefix-cls}-range-start,
      .@{datePicker-prefix-cls}-range-end {
        &::before {
          height: 28px;
        }
      }
    }

    .@{datePicker-prefix-cls}-month {
      &-warpper {
        .@{datePicker-prefix-cls}-month-item {
          overflow: hidden;
          cursor: pointer;

          &:hover {
            .@{datePicker-prefix-cls}-month-text {
              &:not(.@{datePicker-prefix-cls}-month-text-selected) {
                background: #f5f5f5;
              }
            }

            &:not(.@{datePicker-prefix-cls}-month-item-disabled) {
              .@{datePicker-prefix-cls}-month-text-selected {
                background: @date-square-item-color-selected;
              }
            }
          }

          .@{datePicker-prefix-cls}-month-text {
            position: relative;
            z-index: 2;
            width: 48px;
            padding: 2px 5px;
          }

          .@{datePicker-prefix-cls}-month-text-today {
            .today-after(@date-color-background-checked);
          }

          &-disabled {
            pointer-events: none;

            .@{datePicker-prefix-cls}-month-text {
              color: #b2b2b2;
              background: #f5f5f5;
            }
          }

          .@{datePicker-prefix-cls}-month-text-selected {
            background: @date-color-background-checked;
            color: #fff;
          }
        }
      }

      .@{datePicker-prefix-cls}-range-view,
      .@{datePicker-prefix-cls}-range-start,
      .@{datePicker-prefix-cls}-range-end {
        &::before {
          height: 28px;
        }
      }
    }

    .@{datePicker-prefix-cls}-quarter {
      &-warpper {
        display: grid;
        grid-template-columns: 25% 25% 25% 25%;

        .@{datePicker-prefix-cls}-quarter-item {
          overflow: hidden;
          padding-bottom: 0;
          cursor: pointer;

          &:hover {
            .@{datePicker-prefix-cls}-quarter-text {
              &:not(.@{datePicker-prefix-cls}-quarter-text-selected) {
                background: #f5f5f5;
              }
            }

            &:not(.@{datePicker-prefix-cls}-quarter-item-disabled) {
              .@{datePicker-prefix-cls}-quarter-text-selected {
                background: @date-square-item-color-selected;
              }
            }
          }

          .@{datePicker-prefix-cls}-quarter-text {
            position: relative;
            z-index: 2;
            width: 36px;
            padding: 0 5px;
          }

          .@{datePicker-prefix-cls}-quarter-text-today {
            .today-after(@date-color-background-checked);
          }

          &-disabled {
            pointer-events: none;

            .@{datePicker-prefix-cls}-quarter-text {
              color: #b2b2b2;
              background: #f5f5f5;
            }
          }

          .@{datePicker-prefix-cls}-quarter-text-selected {
            background: @date-color-background-checked;
            color: #fff;
          }
        }
      }
    }

    .@{datePicker-prefix-cls}-calendar {
      width: 240px;
      padding: 8px;
      box-sizing: border-box;

      .@{datePicker-prefix-cls}-weektitle {
        display: flex;

        &-item {
          flex: 1;
          height: 32px;
          line-height: 32px;
          cursor: default;
        }
      }

      .@{datePicker-prefix-cls}-calendar-line {
        display: flex;

        .@{datePicker-prefix-cls}-calendar-item {
          flex: 1;
          margin-bottom: 0;
          height: 32px;
          padding: 3px 0;
          cursor: pointer;
          overflow: hidden;
          box-sizing: border-box;
        }

        & .@{datePicker-prefix-cls}-calendar-item:not(.@{datePicker-prefix-cls}-calendar-item-disabled):hover {
          .@{datePicker-prefix-cls}-calendar-text {
            background: #f5f5f5;
          }

          .@{datePicker-prefix-cls}-calendar-text-selected {
            background: @date-square-item-color-selected !important;
          }
        }

        .@{datePicker-prefix-cls}-calendar-item-disabled {
          position: relative;
          cursor: not-allowed;

          .@{datePicker-prefix-cls}-calendar-text {
            color: #b2b2b2;
          }

          .@{datePicker-prefix-cls}-calendar-text-selected {
            color: #fff;
          }

          &::before {
            content: '';
            width: 100%;
            position: absolute;
            z-index: 1;
            background: #f5f5f5;
            height: 24px;
          }
        }
      }

      .@{datePicker-prefix-cls}-calendar-week-line {
        position: relative;
        display: flex;

        .@{datePicker-prefix-cls}-calendar-item {
          flex: 1;
          padding: 0;
          cursor: pointer;

          ::before {
            content: '';
            position: absolute;
            height: 100%;
            width: 100%;
            top: 0;
            left: 0;
            z-index: -1;
          }
        }

        &:hover {
          & .@{datePicker-prefix-cls}-calendar-item:not(.@{datePicker-prefix-cls}-calendar-item-disabled) {
            .@{datePicker-prefix-cls}-calendar-week-text::before {
              background: #f5f5f5;
            }
          }
        }

        &.@{datePicker-prefix-cls}-calendar-week-selected {
          .@{datePicker-prefix-cls}-calendar-week-text::before {
            background: @date-color-background-checked;
          }

          &:hover {
            & .@{datePicker-prefix-cls}-calendar-item:not(.@{datePicker-prefix-cls}-calendar-item-disabled) {
              .@{datePicker-prefix-cls}-calendar-week-text::before {
                background: @date-square-item-color-selected;
              }
            }
          }

          // .@{datePicker-prefix-cls}-calendar-weeknumber{
          //   color: #fff;
          // }
          .@{datePicker-prefix-cls}-calendar-week-text {
            background: transparent !important;
            color: #fff !important;

            &-today {
              .today-after(#fff);
            }
          }
        }

        .@{datePicker-prefix-cls}-calendar-item-disabled {
          cursor: not-allowed;
          pointer-events: none;

          .@{datePicker-prefix-cls}-calendar-week-text {
            color: #b2b2b2;
            background: #f5f5f5;
          }
        }

        .@{datePicker-prefix-cls}-range-start {
          &::before {
            left: 0;
          }
        }

        .@{datePicker-prefix-cls}-range-end {
          &::before {
            right: 0;
          }
        }
      }

      .@{datePicker-prefix-cls}-calendar-text,
      .@{datePicker-prefix-cls}-calendar-week-text {
        position: relative;
        z-index: 2;
        width: @datePicker-calendar-text;
        height: @datePicker-calendar-text;
        text-align: center;
        line-height: @datePicker-calendar-text;
        display: inline-block;
        border-radius: @date-panel-border-radius;
        color: #b2b2b2;

        &-today {
          .today-after(@date-color-background-checked);
        }
      }

      .@{datePicker-prefix-cls}-calendar-week-text {
        width: 100%;
        height: @datePicker-calendar-text;
        margin: 3px 0;
      }

      .@{datePicker-prefix-cls}-calendar-current {
        .@{datePicker-prefix-cls}-calendar-text {
          color: #212121;
        }

        .@{datePicker-prefix-cls}-calendar-week-text {
          color: #212121;
        }

        .@{datePicker-prefix-cls}-calendar-text-selected {
          background: @date-color-background-checked;
          color: #fff;
        }
      }

      .@{datePicker-prefix-cls}-calendar-weeknumber,
      .@{datePicker-prefix-cls}-weektitle-weeknumber {
        width: 24px;
        height: 30px;
        text-align: center;
        line-height: 30px;
        color: #bfbfbf;
        font-weight: bold;
        cursor: default;
      }
    }
  }

  .@{datePicker-prefix-cls}-range-start {
    &::before {
      left: 50%;
    }

    .@{datePicker-prefix-cls}-calendar-text-selected {
      border-top-right-radius: 0 !important;
      border-bottom-right-radius: 0 !important;
    }
  }

  .@{datePicker-prefix-cls}-range-end {
    &::before {
      right: 50%;
    }

    .@{datePicker-prefix-cls}-calendar-text-selected {
      border-top-left-radius: 0 !important;
      border-bottom-left-radius: 0 !important;
    }
  }

  .@{datePicker-prefix-cls}-range-view,
  .@{datePicker-prefix-cls}-range-start,
  .@{datePicker-prefix-cls}-range-end {
    position: relative;

    &::before {
      content: '';
      position: absolute;
      z-index: 1;
      height: 24px;
      width: 100%;
      margin: 0 -4px;
      background: @date-range-item-color-bg;
    }
  }

  .@{datePicker-prefix-cls}-header {
    &-icon {
      min-width: 1.6em;
      font-size: 14px;
      padding: 0;
      color: rgba(0, 0, 0, 0.25);
      background: 0 0;
      border: 0;
      cursor: pointer;
      transition: color 0.3s;

      &:hover {
        color: @date-color-background-checked;
      }
    }

    &-text {
      flex: 1;

      &-inner {
        &-active {
          color: @date-color-background-checked;
        }

        &-hover:hover {
          color: @date-color-background-checked;
          cursor: pointer;
        }

        &:nth-child(2) {
          margin-left: 13px;
        }
      }
    }
  }

  .@{datePicker-prefix-cls}-time-header,
  .@{datePicker-prefix-cls}-header {
    height: @date-panel-header-height;
    line-height: @date-panel-header-height;
    background: #fafafa;
    color: #212121;
    font-size: 14px;
    padding: 7px;
    border-bottom: 1px solid #d9d9d9;
    font-weight: bold;
    display: flex;
    align-items: center;
    box-sizing: border-box;
  }

  .@{datePicker-prefix-cls}-time {
    padding-top: 4px;
    width: auto;

    .@{datePicker-prefix-cls}-content {
      display: flex;
      height: @datePicker-calendar-height;
      border-left: 1px solid #d9d9d9;
      width: 100%;
      table-layout: fixed;
      border-collapse: collapse;

      .@{datePicker-prefix-cls}-time-column {
        flex: 1 0 auto;
        width: 56px;
        margin: 0;
        padding: 10px 0 214px 0;
        text-align: left;
        transition: background 0.3s;
        overflow: hidden;

        &:not(:first-child) {
          border-left: 1px solid #d9d9d9;
        }

        &:hover {
          overflow-y: overlay;
        }

        .@{datePicker-prefix-cls}-time-cell {
          margin: 0;
          padding: 0;

          &-inner {
            display: block;
            width: 100%;
            height: 28px;
            margin: 0;
            text-align: center;
            color: rgba(0, 0, 0, 0.85);
            line-height: 28px;
            border-radius: 0;
            cursor: pointer;
            box-sizing: border-box;
            transition: background 0.3s;

            &:hover {
              background: #f5f5f5;
            }
          }
        }

        .@{datePicker-prefix-cls}-time-cell-selected {
          .@{datePicker-prefix-cls}-time-cell-inner {
            background: @date-range-item-color-bg;
          }
        }

        .@{datePicker-prefix-cls}-time-cell-disabled {
          .@{datePicker-prefix-cls}-time-cell-inner {
            color: rgba(0, 0, 0, 0.25);
            background: transparent;
            cursor: not-allowed;
          }
        }
      }
    }
  }

  .@{datePicker-prefix-cls}-datetime-panel {
    display: flex;

    .@{datePicker-prefix-cls}-time {
      padding: 0;
    }
  }

  .@{datePicker-prefix-cls}-footer {
    width: min-content;
    min-width: 100%;
    line-height: 36px;
    height: 40px;
    border-top: 1px solid #d9d9d9;
    border-bottom: 1px solid transparent;
    padding: 0 12px;
    color: @date-color-background-checked;
    font-size: 12px;
    box-sizing: border-box;
    text-align: right;
    background: @date-footer-color-background;

    &::after {
      content: '';
      vertical-align: middle;
    }

    &-extra {
      line-height: 34px;
      text-align: left;
    }

    .@{datePicker-prefix-cls}-today-btn,
    .@{datePicker-prefix-cls}-ok-btn {
      display: inline-block;
      padding: 5px 12px;
      background: @date-color-background-checked;
      color: #fff;
      border-radius: @date-panel-border-radius;
      line-height: initial;
      vertical-align: middle;
      cursor: pointer;
    }

    .@{datePicker-prefix-cls}-btn-disabled {
      background-color: #e3ebff;
      cursor: not-allowed;
    }

    .@{datePicker-prefix-cls}-btns {
      margin-bottom: 0;
      // padding: 4px 12px;
      overflow: hidden;
      // line-height: 34px;
      text-align: left;
      list-style: none;

      li {
        display: inline-block;

        &::after {
          vertical-align: middle;
        }
      }

      .@{datePicker-prefix-cls}-now {
        text-align: left;
        vertical-align: middle;
        cursor: pointer;
      }

      .@{datePicker-prefix-cls}-ok {
        float: right;
        margin-left: 8px;
        vertical-align: middle;
      }
    }
  }
}

.@{datePicker-prefix-cls}-container {
  display: flex;
  background: @date-container-color-background;

  &-date{
    display: flex;
  }

  .@{datePicker-prefix-cls}-ranges {
    width: 160px;
    color: @date-container-color;
    padding: 0 12px;
    text-align: left;
    overflow: auto;
    max-height: 276px;

    &-item {
      height: @date-panel-header-height;
      line-height: @date-panel-header-height;
      font-size: @date-container-font-size;
      border-bottom: .5px solid @date-container-color-border;
      cursor: pointer;
    }
  }
}
